# Contributor: Bhushan Shah <bshah@kde.org>
# Maintainer: Luca Weiss <luca@lucaweiss.eu>
pkgname=apitrace
pkgver=12.0
pkgrel=1
pkgdesc="Tools for tracing OpenGL, Direct3D, and other graphics APIs"
url="https://apitrace.github.io/"
arch="all"
license="MIT"
depends="python3"
makedepends="
	cmake
	gtest-dev
	libpng-dev
	libx11-dev
	linux-headers
	mesa-dev
	qt5-qtbase-dev
	samurai
	snappy-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
# Update to submodule revision as in https://github.com/apitrace/apitrace/tree/master/thirdparty when updating
_libbacktrace_commit="8602fda64e78f1f46563220f2ee9f7e70819c51d"
source="https://github.com/apitrace/apitrace/archive/$pkgver/apitrace-$pkgver.tar.gz
	https://github.com/ianlancetaylor/libbacktrace/archive/$_libbacktrace_commit/libbacktrace-$_libbacktrace_commit.tar.gz
	no-submodule.patch
	"

prepare() {
	default_prepare

	# Remove bundled libraries, except for some
	rm -rf $(ls -1d thirdparty/* | grep -Ev "(khronos|md5|crc32c|libbacktrace.cmake|support|CMakeLists.txt)")

	# Add bundled libbacktrace
	mv "$srcdir"/libbacktrace-$_libbacktrace_commit \
		thirdparty/libbacktrace
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DENABLE_STATIC_SNAPPY=OFF
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
2af33aec39f43556765455662c69ee22bf3ff5d5fe8b0ca58fe3d555ab1571eab5ddbd4f0011b0c1669043314c8d5166b886ac2825f85d74ebadd9f848598698  apitrace-12.0.tar.gz
8f303ff11250cbc644c91a07a55ffb1c6d52ca5eb76e3ea9405645bdd00715a25f57d1f39c7af16efbbe5b008ec76890f7fb3bca95eb89e7cd9a55c14a211643  libbacktrace-8602fda64e78f1f46563220f2ee9f7e70819c51d.tar.gz
75a80462c1a873ce411fd89a33f0ee2b646c20d4ef70d8b75c5336fc8c2f95a69ce05194ef7d31fda752c6fb4e93c776d8ef7adff201b0916be389a82d8f5482  no-submodule.patch
"
